<template>
  <div>
    <el-tabs v-model="activeNewName" @tab-click="handleNewClick" type="card">
      <el-tab-pane label="机构信息" name="one">
        <el-row>
          <el-col :span="24">
            <el-form :model="queryEnterpriseParams" ref="queryFormEnterprise" size="small" :inline="true"
                     v-show="showSearch" label-width="100px">
              <el-form-item label="企业名称" prop="enterpriseName">
                <el-input v-model="queryEnterpriseParams.deptName" placeholder="请输入企业名称" clearable
                          @keyup.enter.native="handleQueryEnterprise" />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini"
                           @click="handleQueryEnterprise">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini"
                           @click="resetQueryEnterprise">重置</el-button>
                <el-button type="primary" size="mini" @click="saveSelectEnterprise">确定</el-button>
              </el-form-item>
            </el-form>
            <el-table ref="tableEnterprise" v-loading="loading" style="width: 100%"
                      @selection-change="handleSelectionChangeEnterprise" :data="infoList">
              <el-table-column type="selection" width="45" align="center" />
              <el-table-column label="企业名称" align="center" prop="deptName" />
              <el-table-column label="联系人" align="center" prop="contacts" />
              <el-table-column label="联系电话" align="center" prop="phone"
                               show-overflow-tooltip="true" />
            </el-table>
            <pagination v-show="total1 > 0" :total="total1" :page.sync="queryEnterpriseParams.pageNum"
                        :limit.sync="queryEnterpriseParams.pageSize" @pagination="getEnterpriseList" />
          </el-col>
        </el-row>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>
<script>
import { getOrgListAll} from '@/api/system/dept'
export default {
  name:"changeEnter",
  data(){
    return{
      activeNewName: 'one',
      // 显示搜索条件
      showSearch: true,
      infoList: [],
      seasList: [],
      electricList: [],
      collList:[],

      // 选中数组
      eIds: [],
      sIds: [],
      eleIds:[],
      collIds:[],
      eName: [],
      sName: [],
      eleName:[],
      collName:[],
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      total1: 0,
      total2: 0,
      total3:0,
      total4:0,
      queryEnterpriseParams: {
        pageNum: 1,
        pageSize: 5,
        deptName: null
      },
    }
  },
  created() {
    this.getEnterpriseList();
  },
  methods:{
    handleNewClick(tab, event) {
      this.$refs.tableSeas.clearSelection();
    },
    /** 搜索按钮操作 */
    handleQueryEnterprise() {
      this.queryEnterpriseParams.pageNum = 1;
      this.getEnterpriseList();
    },
    getEnterpriseList() {
      this.loading = true;
      getOrgListAll(this.queryEnterpriseParams).then(response => {
        this.infoList = response.rows;
        this.total1 = response.total;
        this.loading = false;
      });
    },


    /** 重置按钮操作 */
    resetQueryEnterprise() {
      this.resetForm("queryFormEnterprise");
      this.queryEnterpriseParams.deptName = null;
      this.handleQueryEnterprise();
    },
    saveSelectEnterprise() {
      console.log(this.eIds.toString())
      console.log(this.eName.toString())
      if (this.eIds.length > 0){
        this.$emit('select-enterprise', {
          enterpriseName: this.eName.toString(),
          enterpriseId: this.eIds.toString()
        });
      }else {
        this.$message.error("请选择企业");
      }
    },
    handleSelectionChangeEnterprise(selection) {
      if (selection.length > 1) {
        this.$refs.tableEnterprise.clearSelection(); // 清空所有选择
        this.$refs.tableEnterprise.toggleRowSelection(selection.pop()); // 设置选择项
      } else {
        this.eIds = selection.map(item => item.deptId)
        this.eName = selection.map(item => item.deptName)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      }
    },
  }
}
</script>
<style scoped lang="scss">
::v-deep .el-table .el-table__header-wrapper .el-checkbox {
  display: none;
}

::v-deep .el-dialog__header {
  padding-top: 5px;
}
</style>
